<template>
	<div id="user-edit">
		<Form ref="formValidate" :label-width="100" :model="parms" :rules="ruleValidate" label-position="right">
			<FormItem label="账号状态:" prop="statuz">
				<i-switch
					v-model="parms.statuz"
					:false-value="0"
					:true-value="1"
				>
					<span slot="0">On</span>
					<span slot="1">Off</span>
				</i-switch>
			</FormItem>
			<FormItem label="登录账号:" prop="loginName">
				<Input v-model="parms.loginName" placeholder="建议使用用户手机号"/>
			</FormItem>
			<FormItem label="姓名:" prop="nickName">
				<Input v-model="parms.nickName" placeholder="请输入姓名"/>
			</FormItem>
			<FormItem label="密码:" prop="nickName">
				<Input v-model="parms.loginPwd" placeholder="请输入密码" type="password"/>
			</FormItem>
		</Form>
		<div style="text-align: center">
			<Button type="primary" @click="saveAdmins">保存</Button>
		</div>
	</div>
</template>

<script>
import {deepCopy} from "view-design/src/utils/assist";
import {extend} from "@/libs/tools";

export default {
	name: "user-edit",
	props: ['selectItem'],
	data() {
		return {
			parms: {
				id: '',
				loginName: '',
				nickName: '',
				statuz: 1,
				loginPwd: '',
				createTime: '',
			},
			enterpriseList: [],
			ruleValidate: {
				loginName: [{required: true, message: '请输入账号', trigger: 'blur'}],
				nickName: [{required: true, message: '请输入姓名', trigger: 'blur'}],
				loginPwd: [{required: true, message: '请输入密码'}],
			}
		};
	},
	mounted() {
		this.parms = extend(this.parms, this.selectItem)
	},
	methods: {
		//添加用户
		saveAdmins() {
			this.$refs.formValidate.validate(es => {
				if (!es) return
				let parms = deepCopy(this.parms);
				if (Object.keys(this.selectItem).length > 0) {
					this.$emit('edit', parms)
				} else {
					this.$emit('add', parms)
				}
			})
		}
	}
};
</script>
<style scoped>

</style>
